﻿<UserControl x:Class="Spenta.StreetCare.Silverlight.UserControls.ReportsMapUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    xmlns:ViewModels="clr-namespace:Spenta.StreetCare.Silverlight.MVVM.ViewModels"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4" 
    xmlns:UserControls="clr-namespace:Spenta.StreetCare.Silverlight.UserControls" mc:Ignorable="d">

    <UserControl.Resources>
        <ViewModels:ReportsViewModel x:Key="ReportsViewModel"/>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource ReportsViewModel}}" d:DataContext="{d:DesignData /SampleData/ReportsViewModelSampleData.xaml}">
        <m:Map CredentialsProvider="{Binding Customer.CustomerMapCredentials}" AnimationLevel="Full" Culture="{Binding Culture}" x:Name="map">
            <m:Map.Mode>
                <m:AerialMode Labels="True" AnimationLevel="Full" />
            </m:Map.Mode>
            <m:MapItemsControl ItemsSource="{Binding Reports}">
                <m:MapItemsControl.ItemTemplate>
                    <DataTemplate>
                        <m:Pushpin Cursor="Hand" Location="{Binding ReportMapLocation}" Background="{Binding Category.CategoryColor, Converter={StaticResource PushpinTypeBrushConverter}}"  >
                            <Image Source="{Binding Category.CategoryImageUrl}" />
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseLeftButtonDown">
                                    <cmd:EventToCommand Command="{Binding Source={StaticResource ReportsViewModel}, Path=SelectReportCommand, Mode=OneWay}"
                                                    CommandParameter="{Binding}"
                                                    MustToggleIsEnabledValue="True" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </m:Pushpin>
                    </DataTemplate>
                </m:MapItemsControl.ItemTemplate>
            </m:MapItemsControl>
            <m:MapLayer>
                <Canvas x:Name="ReportBubbleCanvas" Visibility="{Binding BubbleVisible, Converter={StaticResource VisibilityToBoolConverter}}" Opacity="0.95" m:MapLayer.PositionOffset="15,-70">
                    <UserControls:ReportBubbleUserControl />
                </Canvas>
            </m:MapLayer>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="ViewChangeStart">
                    <cmd:EventToCommand Command="{Binding Source={StaticResource ReportsViewModel}, Path=UnselectReportCommand, Mode=OneWay}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </m:Map>
    </Grid>
</UserControl>
